﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace ConsoleApp
{
    public static class ConsoleHelper
    {
        public static void Write(string content)
        {
            OverWrite(content, (char c) => Console.Write(c));
        }
        public static void Write(string content,ConsoleColor color)
        {
            Console.ForegroundColor = color;
            OverWrite(content, (char c) => Console.Write(c));
            Console.ForegroundColor = ConsoleColor.White;
        }

        public static void WriteLine(string content)
        {
            OverWrite(content, (char c)=> Console.Write(c));
            OverWrite("\n", (char c) => Console.Write(c));
        }
        public static void WriteLine(string content, ConsoleColor color)
        {
            Console.ForegroundColor = color;
            OverWrite(content, (char c) => Console.Write(c));
            OverWrite("\n", (char c) => Console.Write(c));
            Console.ForegroundColor = ConsoleColor.White;
        }

        public static void OverWrite(string content,Action<char> action)
        {
            if (string.IsNullOrEmpty(content))
                return;
            char[] wordArray = content.ToCharArray();
            foreach (var word in wordArray)
            {
                Thread.Sleep(100);
                action.Invoke(word);
            }
        }
        

    }
}
